﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace winApp2
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            RefData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RefData();
        }

        Process[] procs;
        private void RefData()
        {
            //获取当前所进程
            procs = Process.GetProcesses();
            listBox1.Items.Clear();
            foreach (var p in procs)
            {
                listBox1.Items.Add(p.ProcessName);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;
            if (n == -1)
            {
                UITools.Msg("请选择!");
                return;
            }
            var p = procs[n];

            try
            {
                //Clipboard.Clear(); //剪贴板
                p.Kill();
                UITools.Msg("终止成功!");
                RefData();
            }
            catch (Exception ex)
            {
                UITools.Msg("终止失败!\n原因:"+ex.Message);
            }
        }
    }
}
